import { createStore } from 'vuex'
import persist from 'vuex-persistedstate'
import {getloginid} from "../utlis/api"

interface UserConfig {
  nickName: string
  token: string
  column: string
  email: string
  _id: string
}
export default createStore({
  state: <UserConfig>{
    token: '',
    nickName: '',
    _id: "",
    column: ""
  },
  getters: {
    id(state){
      return state._id
    }
  },
  mutations: {
    // 登录
   async login(state: UserConfig, obj) {
      state.token = obj
       await getloginid().then(res => {
          console.log(271111,res);
          state._id=res.data._id
          state.nickName=res.data.nickName
          state.column=res.data.column
        })
      
    },
    // 退出登录
    reun(state) {
      state.token = ""
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [persist()],
})
